<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>优惠券管理</title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body>
<div class="layui-panel"style="padding: 8px;">
    <fieldset class="layui-elem-field layui-border-green">
        <legend>信息</legend>
        <form class="layui-form layui-form-pane" style="margin: 20px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="name"autocomplete="off" />
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <a class="layui-btn layui-btn-primary"lay-submit="" lay-filter="searchBtn">
                            <li class="layui-icon layui-icon-search">搜索</li>
                        </a>
                    </div>
                </div>
            </div>
        </form>
    </fieldset>
</div>
<table class="layui-hide" id="couponsTable" lay-filter="couponsTable"></table>
<script id="tool"type="text/html" >
    <a class="layui-btn layui-btn-normal layui-btn-xs"lay-event="details">详情</a>
    <a class="layui-btn layui-btn-xs layui-btn-xs"lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs"lay-event="delete">删除</a>
</script>
<script>
    var $;
   /* var data=[{"id":1,"name":"可兑换优惠券","introduce":"全场通用","label":"仅兑换领券","minConsume":"满99元可用","reduction":"减免15元","limit":1,"area":"指定商品","type":"兑换码","number":"不限","status":1}]*/
    layui.use(['table','rate','jquery'], function(){
        var table = layui.table,
            rate=layui.rate;
        $=layui.jquery;
        table.render({
            elem: '#couponsTable',
            page:true,
            limit:10,
            limits:[5,10,20,30],
            url:'/system/cp/find',
            toolbar:'#tableBar',
            cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增,
            cols: [
                [
                    {type:'checkbox',fixed:'left'},
                    {field:'id', width:105, title: '序列ID',align: 'center', sort: true},
                    {field:'name', width:220, title: '优惠券名称',align: 'center', sort: true,
                     templet:function (obj){
                        var isNew = obj.name;
                        var str = "";
                        if(isNew==0){
                            str = "<span style='font-family:SimHei;font-size:16px'>可兑换优惠券</span>"
                        }else if(isNew==1){
                            str = "<span  style='font-family:SimHei;font-size:16px'>限时满减券</span>"
                        }
                        else if(isNew==2){
                            str = "<span style='font-family:SimHei;font-size:16px'>新用户优惠券</span>"
                        }else{
                            str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                        }
                        return str;
                    }},
                    {field:'introduce', width:210,title: '介绍',align: 'center', sort: true,
                        templet:function (obj){
                            var isNew = obj.introduce;
                            var str = "";
                            if(isNew==0){
                                str = "<span style='font-family:SimHei;font-size:16px'>全场通用</span>"
                            }else if(isNew==1){
                                str = "<span  style='font-family:SimHei;font-size:16px'>仅限部分活动使用</span>"
                            } else{
                                str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                            }
                            return str;
                        }},
                    {field:'label', width:210,title: '标签',align: 'center', sort: true,
                        templet:function (obj){
                            var isNew = obj.label;
                            var str = "";
                            if(isNew==0){
                                str = "<span style='font-family:SimHei;font-size:16px;color: #fc0505'>仅兑换领券</span>"
                            }else if(isNew==1){
                                str = "<span  style='font-family:SimHei;font-size:16px;color: #00ee00'>无限制</span>"
                            } else{
                                str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                            }
                            return str;
                        }
                    },
                    {field:'minConsume', width:143,title: '最低消费',align: 'center', sort: true,
                        templet:function (obj){
                            var isNew = obj.minConsume;
                            var str = "";
                            str = "<span style='font-family:SimHei;font-size:16px'>满</span>"+isNew+"<span>元可用</span>";
                            return str;
                        }
                    },
                    {field:'reduction', width:131,title: '满减金额',align: 'center', sort: true,
                        templet:function (obj){
                            var isNew = obj.reduction;
                            var str = "";
                            str = "<span style='font-family:SimHei;font-size:16px'>减免</span>"+isNew+"<span>元</span>";
                            return str;
                        }
                    },
                    {field:'limits', width:112,title: '每人限领',align: 'center', sort: true},
                    {field:'area', width:156,title: '使用范围',align: 'center', sort: true
                        ,
                        templet:function (obj){
                            var isNew = obj.area;
                            var str = "";
                            if(isNew==0){
                                str = "<span style='font-family:SimHei;font-size:16px'>指定商品</span>"
                            }else if(isNew==1){
                                str = "<span  style='font-family:SimHei;font-size:16px'>全场通用</span>"
                            } else{
                                str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                            }
                            return str;
                        }
                    },
                    {field:'type', width:160,title: '优惠券类型',align: 'center', sort: true,
                        templet:function (obj){
                            var isNew = obj.type;
                            var str = "";
                            if(isNew==0){
                                str = "<span style='font-family:SimHei;font-size:16px'>兑换码</span>"
                            }else if(isNew==1){
                                str = "<span  style='font-family:SimHei;font-size:16px'>通用领券</span>"
                            }
                            else if(isNew==2){
                                str = "<span  style='font-family:SimHei;font-size:16px'>注册赠券</span>"
                            }
                            else{
                                str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                            }
                            return str;
                        }
                    },
                    {field:'number', width:130,title: '优惠券数量',align: 'center', sort: true
                        ,
                        templet:function (obj){
                            var isNew = obj.number;
                            var str = "";
                            if(isNew==0){
                                str = "<span style='font-family:SimHei;font-size:16px;color: #53c70b'>不限</span>"
                            }else if(isNew==1){
                                str = "<span  style='font-family:SimHei;font-size:16px;color: #797777'>有限制</span>"
                            }
                            else{
                                str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                            }
                            return str;
                        }
                    },
                    {field:'status', width:100,title: '状态',align: 'center', sort: true
                        ,
                        templet:function (obj){
                            var isNew = obj.status;
                            var str = "";
                            if(isNew==0){
                                str = "<span style='font-family:SimHei;font-size:16px;color: #00ee00'>正常</span>"
                            }else if(isNew==1){
                                str = "<span  style='font-family:SimHei;font-size:16px;color: #9a9898'>已过期</span>"
                            } else{
                                str = "<span style='font-family:SimHei;font-size:16px;color: #dc0a0a'>Unknown</span>"
                            }
                            return str;
                        }
                    },
                    {fixed:'right',title:'操作',width:180,align:'center',toolbar:'#tool'}
                ]
            ]
            /*,data:data,*/
        });
        var active={
            dialog:function (content){
                var b = false;
                layer.open({
                    type:2,
                    content:content,
                    area:['800px','750px'],
                    maxmin:true,
                    btn:['确认','关闭'],
                    btn1:function (i,o) {
                        b = true;
                        o.find('iframe')[0].contentWindow.btnSubmit23();
                    },
                    end:function () {
                        if(b) layui.table.reload('couponsTable');
                    }
                })
            },
            deleted:function (id){
                $.ajax({
                    type:'post',
                    url: '/system/cp/delete?id='+id,
                    dataType:'json',
                    success:function (result) {
                        layer.msg(result.msg);
                        if(result.is){
                            let index =parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭父页面窗口
                        }
                    }
                })
            }
        }

        table.on('tool(couponsTable)',function (obj) {
            var event = obj.event;
            if("details" == event){
               /* alert("这是详情功能"+obj.data.id)*/
                active.dialog('/page/system/couponsLook/'+obj.data.id);
            }
            else if("edit"==event){
               /* alert("这是编辑功能")*/
                active.dialog('/page/system/couponsDate/'+obj.data.id);//todo
            }
            else if("delete"==event){
                layer.confirm("确认要删除ID为"+obj.data.id+"的评论吗",function (){
                    active.deleted(obj.data.id);
                })
            }
        })

    });
</script>

</body>
</html>